<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<base href="<%=basePath%>">
	<title>hr-m-s</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/style.css" >
	<script type="text/javascript" src="<%=basePath%>js/jquery-1.7.2.js" ></script>
</head>
<body>
<form id="user_edit" name="user_edit" method="post" action="user!update">
  <table width="800" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <th colspan="3" scope="col">修改系统用户信息</th>
    </tr>
    <tr>
      <td width="100">用户账号</td>
      <td>
        <input name="userAccount" type="text" id="userAccount" size="50" maxlength="50" value='<s:property value="user.userAccount"/>'/>
      </td>
      <td width="200">
        <input name="checkAccount" type="button" id="checkAccount" value="检查重复"/>
      </td>
    </tr>
    <tr>
      <td>登陆密码</td>
      <td>
        <input name="userPassword" type="password" id="userPassword" size="50" maxlength="50" />
      </td>
      <td>不少于6位<br></td>
    </tr>
    <tr>
      <td>确认密码</td>
      <td><input name="confirmUserPassword" type="password" id="confirmUserPassword" size="50" maxlength="50" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>所属权限组</td>
      <td>
        <select name="authorityGroupID" id="authorityGroupID">
          <option value="0">请选择</option>
          <s:iterator value="authorityGroupList" var="list">
          	<s:if test="user.authorityGroupID == authorityGroupID">
          		<option value='<s:property value="authorityGroupID"/>' selected="selected"><s:property value="authorityGroupName"/></option>
          	</s:if>
          	<s:else>
          		<option value='<s:property value="authorityGroupID"/>'><s:property value="authorityGroupName"/></option>
          	</s:else>
          </s:iterator>
        </select>
      </td>
      <td>分配权限组给系统用户</td>
    </tr>
    <tr>
      <td>是否启用</td>
      <td>
        <select name="userDisplayKey" id="userDisplayKey">
          <s:if test="user.userDisplayKey = 1">
	        <option value="1" selected="selected">启用</option>
	        <option value="0">停用</option>
	      </s:if>
	      <s:else>
	        <option value="1">启用</option>
	        <option value="0" selected="selected">停用</option>
	      </s:else>
        </select>
      </td>
      <td>控制显示</td>
    </tr>
    <tr>
      <td colspan="3">
      	<input name="userID" type="hidden" id="userID" value='<s:property value="userID"/>'/>
        <input name="submit" type="submit" id="submit" value="修改" />
        <input name="reset" type="reset" id="reset" value="重置" onclick="javascript:return confirm('确定要重新填写所有数据吗？');"/>
      </td>
    </tr>
  </table>
</form>
<div id="showMessage" align="center"><s:property value="messageTips" /></div>
<script type="text/javascript">
	$(function(){
    		$("#submit").click(function(){
    			if($("#userAccount").val()==""){
      				alert("请输入登录账号!");
      				$("#userAccount").focus();
     				return false;
     			}
     			if($("#userPassword").val() != ""){
	     			if($("#userPassword").val().length < 6){
	      				alert("密码不能少于6位!");
	      				$("#userPassword").focus();
	     				return false;
	     			}
     			}
     			if($("#userPassword").val() != $("#confirmUserPassword").val()){
      				alert("两次输入的密码不一致!");
      				$("#confirmUserPassword").focus();
     				return false;
     			}
     			if($("#authorityGroupID").find("option:selected").index()==0){
      				alert("请选择所属权限组!");
      				$("#authorityGroupID").focus();
     				return false;
     			}
    		});
    		$("#checkAccount").click(function(){
     			var userAccount= $("#userAccount").val();
     			if (userAccount == ""){
     				alert("请输入用户账号");
     				$("#userAccount").focus();
     				return false;
     			} else {
					$.ajax({
						url : "ajaxJson!isUserExists",
						type: "post",
						data: "userAccount=" + userAccount,
						success: function(data){
							alert(data.message);
						},
						error: function(){
	      					alert("出错了，请稍后再试！");
	     				}
					});
				}
    		});
  		});
</script>
</body>
</html>
